import 'package:get/get.dart';

import '../../../service/xin_he_reqest.dart';
import '../../../utils/xin_he_storage.dart';
import '../../../utils/xin_he_toast.dart';
import 'xin_he_oil_card_exchange_state.dart';

class XinHeOilCardExchangeLogic extends GetxController {
  final XinHeOilCardExchangeState state = XinHeOilCardExchangeState();

  RxString count = ''.obs;

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
  }


  handleSelectedMethod(bool isSelectedFirst){
    print('sssssssssssssss');
    if(isSelectedFirst == state.isSelectedFirst.value){
      return;
    }
    state.isSelectedFirst.value = isSelectedFirst;
  }


  sureExchange() async {

    var userId = await XinHeLocalStorage.get(XinHeStorage.userId);
    Map<String,dynamic> ss = {
      'userId': userId,
      'number':count.value,
      'type': state.isSelectedFirst.value?0:1
    };

    XinHeRequestDataResult result = await XinHeHttpRequestData.requestUniversalPost(url: '/teaOilCardRecord/saveTeaOilCardRecord',params: ss,isPostAndwwwForm: true);
    if(!result.result || result.data['code'] != 0) {
      XinHeToast.center(result.data['message']);
      return ;
    }

    XinHeToast.center('兑换成功');
    Get.back();


  }



}
